/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package danceserver;

import java.awt.Button;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import processing.core.PApplet;

/**
 *
 * @author Arthur
 */
public class Controller extends PApplet implements ActionListener {

    View _view;
    Frame f;
    private Button b;
    private Button c;
    private Button d;
    private Button e;
    String effect;
    Model _model;
    Thread xbeeListener;

    @Override
    public void setup() {

        createFrame();
        size(600, 600, P3D);
        background(0);
        _view = new View(this, this);
        effect = "OFF";
    }

    @Override
    public void draw() {

        _view.draw(VisType.valueOf(effect));
    }

    public void setValues(Vector<Integer> values, long time) {
        int i = 0;
        _view.xJProgressBar.setValue(values.elementAt(i));
        _view.xLabel.setText("   X:" + (values.elementAt(i)));
        _view.setxReading(values.elementAt(i++));

        _view.yJProgressBar.setValue(values.elementAt(i));
        _view.yLabel.setText("   Y:" + (values.elementAt(i)));
        _view.setyReading(values.elementAt(i++));

        _view.zJProgressBar.setValue(values.elementAt(i));
        _view.zLabel.setText("   Z:" + (values.elementAt(i)));
        _view.setzReading(values.elementAt(i));
    }

    public void createFrame() {

        _model = new Model(this);
        xbeeListener = new Thread(_model);
        xbeeListener.start();
    }

    public void actionPerformed(ActionEvent e) {
        System.out.println("got action");
        Button source = (Button) e.getSource();
        String _buttonName = source.getLabel();
        if (_buttonName.equals("Exit") || _buttonName.equals("2g/6g")) {
            _model.action(_buttonName);
        }
        if (_buttonName.equals("CUBES") || _buttonName.equals("SUN") || _buttonName.equals("SPHERE") || _buttonName.equals("LIGHTS")) {
            this.setEffect(_buttonName);
        }
    }

    public void setEffect(String effect) {
        this.effect = effect;
    }
}
